Im new to DXlprogramming, Thanks to developerworks Forum. i get max help from it. |
Re: To find whether an attributeValue of 1 module exists in another module
Welcome to this forum!
for o1 in m1 do
{
string eValue1 = o1.attr ""
for o2 in m2 do
{
string eValue2 = o2.attr ""
if (eValue1 == eValue2){print "\n" eValue1 " matches"}
}
}
then you quickly run into problems as this script will require a very long time to run if the Modules are large enough. The solution to the problem is the use of Skip lists, such that you have to loop through each Module only once. Now, Skip lists might a bit heavy to start with if you are new to DXL, but here you go. A Skip list is a list of key/value pairs, and in the example below we use two Skip lists, one for each Module, where in each list the key is each attribute value appearing in the Module, and the value is a list of Objects in which the attribute value appears (plus a note if the attribute (also) is a Module level attribute).
pragma runLim, 0
// =============================================================================
Skip S_getAttValueList(Module M_mod, string s_attrName)
{ // Get a list of all attribute values in the Module
// key : string attribute value
// value: comma-separated list of Object Absolute Numbers
// and / or indication that it is a Module level attribute
// Note : no specific treatment of multi-value enumeration-type attributes
Skip S_attValueList = null
Object O_obj
AttrDef A_ad
string s_Key, s_Value
A_ad = find(M_mod, s_attrName)
if (!null A_ad)
{ // Attribute does not exist in Module
S_attValueList = createString
if (A_ad.object)
{ // Object level attribute
for O_obj in entire M_mod do
{ // Loop through all (undeleted) Objects
if (isDeleted O_obj){continue}
if (table O_obj){continue}
if (row O_obj){continue}
s_Key = O_obj.s_attrName
if (s_Key == "") {continue}
if (find(S_attValueList, s_Key, s_Value)){s_Value = s_Value "," O_obj."Absolute Number" ""}
else {s_Value = O_obj."Absolute Number" ""}
put(S_attValueList, s_Key, s_Value, true)
} // Loop through all (undeleted) Objects
} // Object level attribute
if (A_ad.module)
{ // Module level attribute
s_Key = M_mod.s_attrName
if (s_Key != "")
{ // Attribute is not empty
if (find(S_attValueList, s_Key, s_Value)){s_Value = s_Value "," "Module level attribute"}
else {s_Value = "Module level attribute"}
put(S_attValueList, s_Key, s_Value, true)
} // Attribute is not empty
} // Module level attribute
} // Attribute does not exist in Module
return S_attValueList
} // Get a list of all attribute values in the Module
// =============================================================================
void v_showAttributeValuePairs(Module M_mod1, M_mod2, string s_attrName)
{ // Search attribute value pairs in two Modules
Skip S_attValueListMod1 = S_getAttValueList(M_mod1, s_attrName)
Skip S_attValueListMod2 = S_getAttValueList(M_mod2, s_attrName)
string s_Key, s_Value1, s_Value2
if (!null S_attValueListMod1 && !null S_attValueListMod2)
{ // Attribute exists in both Modules
for s_Value1 in S_attValueListMod1 do
{ // Loop through Attribute Values in Module 1
s_Key = (string key S_attValueListMod1)
if (find(S_attValueListMod2, s_Key, s_Value2)){print "\n" s_Key "\n\t" (name M_mod1) ": " s_Value1 "\n\t" (name M_mod2) ": " s_Value2} // Found the same attribute value in Module 2
} // Loop through Attribute Values in Module 1
delete S_attValueListMod1
delete S_attValueListMod2
} // Attribute exists in both Modules
else
{ // Attribute does not exist in at least one of the Modules
if (null S_attValueListMod1){print "\nAttribute '" s_attrName"' does not exist in Module '" (fullName M_mod1) "'"}
if (null S_attValueListMod2){print "\nAttribute '" s_attrName"' does not exist in Module '" (fullName M_mod2) "'"}
} // Attribute does not exist in at least one of the Modules
} // Search attribute value pairs in two Modules
You can use the routine like this:
Module m1 = read("<Module 1 path and name>", false, true)
Module m2 = read("<Module 1 path and name>", false, true)
close m1
close m2
Cheers, |
Re: To find whether an attributeValue of 1 module exists in another module Regards Anurag |